package cn.netjava.wk;


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class FileActionTest {
	public static void main(String[] args) throws Exception {
		FileCount fco = new FileCount();
		String[] ss = new String[5];
		for (int i = 0; i < ss.length; i++) {
			ss[i] = null;
		}
		System.out.println("This File action has these using:");
		System.out
				.println("Copy file,Create a new File,delete a canwrite File,search a File!");
		System.out.println("Now please follow the system instructions input!");
		BufferedReader buff = new BufferedReader(new InputStreamReader(
				System.in));
		System.out.println("Copy: copy " + "Delete :delete  "
				+ "Search : search " + "Create: create  "
				+ " CountFilesize: count");
		System.out
				.println("IF your want to quit this System,please input quit!");
		ss[4] = buff.readLine();
		while (!ss[4].equalsIgnoreCase("quit")) {
			
			if (ss[4].equalsIgnoreCase("copy")) {
				System.out
						.println("Please give your source File's or directory absolutpath!");
				ss[1] = buff.readLine();
				System.out
						.println("Please give your destination File's or directory absoultpath");
				ss[2] = buff.readLine();
				FileCopy fc = new FileCopy(ss[1], ss[2]);
				fc.canCopy();

			
			} else if (ss[4].equalsIgnoreCase("delete")) {

				System.out.println("Please give your filename!");
				ss[2] = buff.readLine();
				FileThreadDelete fd = new FileThreadDelete(ss[2]);
			
			
			} else if (ss[4].equalsIgnoreCase("search")) {

				System.out.println("Please give your filename or filenameEnd!");
				ss[2] = buff.readLine();
				FileSearchThread fs = new FileSearchThread(ss[2]);
			
			
			} else if (ss[4].equalsIgnoreCase("create")) {
				System.out.println("Please give your file's root");
				System.out.println("The root must be exits!");
				ss[0] = buff.readLine();
				System.out.println("Please give your prefilename!");
				System.out
						.println("The prefilename length can not be less than three chars!");
				ss[1] = buff.readLine();
				System.out
						.println("Do you want to create a file or a directory! file: file? directory:dir");
				ss[2] = buff.readLine();
				System.out
						.println("Please give your filename attribute!canwrite or canread");
				ss[3] = buff.readLine();
				FileCreate fcr = new FileCreate(ss[0], ss[1], ss[2], ss[3]);
				if (fcr.createFile()) {
					System.out.println("This file has created successfully!");
				} else {
					System.out.println(" Create this file failure!");
				}
			
			
			} else if (ss[4].equalsIgnoreCase("count")) {
				System.out.println("Please give your direcotry!");
				ss[1] = buff.readLine();
				System.out.println("The directory size is:"
						+ fco.fileSize(ss[1]));
			}
			System.out.println("Do you need other service! no:quit! ");
			ss[4] = buff.readLine();
		}
		buff.close();
	}
}
